<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12" >
            <a-form-model-item label="学生名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stuId">
              <a-select
                show-search
                placeholder="请选择学生"
                option-filter-prop="children"
                style="width: 200px"
                v-model='model.stuId'
              >
                  <a-select-option :value='item.stuId'  v-for='(item,index) in stuList' :key='index'>
                    {{item.stuName}}
                  </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" >
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employmentResumeSex">
              <j-dict-select-tag type="radio" v-model="model.employmentResumeSex" dictCode="sex" placeholder="请选择性别" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12" >
            <a-form-model-item label="出生年月" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employmentResumeBirthday">
              <j-date placeholder="请选择出生年月" v-model="model.employmentResumeBirthday" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12" >
            <a-form-model-item label="当前身份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employmentResumeIdentity">
              <j-dict-select-tag type="list" v-model="model.employmentResumeIdentity" dictCode="essential_information_identity" placeholder="请选择当前身份" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="12" >
            <a-form-model-item label="户口所在地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentResidence">
		      <j-area-linkage type="cascader" v-model="model.currentResidence" placeholder="请选择户口所在地" />
            </a-form-model-item>
          </a-col>-->
          <a-col :span="12">
            <a-form-model-item label="户籍所在地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentResidence">
              <a-input v-model="model.currentResidence" placeholder="请输入户籍所在地"  ></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="12" >
            <a-form-model-item label="现居住地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="newCity">
		      <j-area-linkage type="cascader" v-model="model.newCity" placeholder="请选择现居住地" />
            </a-form-model-item>
          </a-col>-->
          <a-col :span="12">
            <a-form-model-item label="现居住地" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="newCity">
              <a-input v-model="model.newCity" placeholder="请输入现居住地"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" >
            <a-form-model-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tel">
              <a-input v-model="model.tel" placeholder="请输入联系方式" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" >
            <a-form-model-item label="电子邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mailbox">
              <a-input v-model="model.mailbox" placeholder="请输入电子邮箱" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12" >
            <a-form-model-item label="简历附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="resumeAttachment">
              <j-upload v-model="model.resumeAttachment"  ></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
      <!-- 子表单区域 -->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="教育经历" :key="refKeys[0]" :forceRender="true">
        <j-vxe-table
          keep-source
          :ref="refKeys[0]"
          :loading="educationExperienceTable.loading"
          :columns="educationExperienceTable.columns"
          :dataSource="educationExperienceTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :toolbar="true"
          />
      </a-tab-pane>
      <a-tab-pane tab="求职意向" :key="refKeys[1]" :forceRender="true">
        <j-vxe-table
          keep-source
          :ref="refKeys[1]"
          :loading="positonIntentionTable.loading"
          :columns="positonIntentionTable.columns"
          :dataSource="positonIntentionTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :toolbar="true"
          />
      </a-tab-pane>
      <a-tab-pane tab="项目经历" :key="refKeys[2]" :forceRender="true">
        <j-vxe-table
          keep-source
          :ref="refKeys[2]"
          :loading="projectExperienceTable.loading"
          :columns="projectExperienceTable.columns"
          :dataSource="projectExperienceTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :toolbar="true"
          />
      </a-tab-pane>
      <a-tab-pane tab="工作经历" :key="refKeys[3]" :forceRender="true">
        <j-vxe-table
          keep-source
          :ref="refKeys[3]"
          :loading="workExperienceTable.loading"
          :columns="workExperienceTable.columns"
          :dataSource="workExperienceTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :toolbar="true"
          />
      </a-tab-pane>
    </a-tabs>
  </a-spin>
</template>

<script>

  import { getAction } from '@/api/manage'
  import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
  import { JVXETypes } from '@/components/jeecg/JVxeTable'
  import { getRefPromise,VALIDATE_FAILED} from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'

  export default {
    name: 'EmploymentResumeForm',
    mixins: [JVxeTableModelMixin],
    components: {
      JFormContainer,
    },
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        model:{
            employmentResumeSex:1,
         },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
           stuId: [
              { required: true, message: '请选择学生!'},
           ],
           employmentResumeSex: [
              { required: true, message: '请选择性别!'},
           ],
           employmentResumeBirthday: [
              { required: true, message: '请输入出生年月!'},
           ],
           employmentResumeIdentity: [
              { required: true, message: '请选择当前身份!'},
           ],
           currentResidence: [
              { required: true, message: '请输入户口所在地!'},
           ],
           newCity: [
              { required: true, message: '请输入现居住地!'},
           ],
           tel: [
              { required: true, message: '请输入联系方式!'},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
           ],
           mailbox: [
              { required: true, message: '请输入电子邮箱!'},
              { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!'},
           ],
        },
        refKeys: ['educationExperience', 'positonIntention', 'projectExperience', 'workExperience', ],
        tableKeys:['educationExperience', 'positonIntention', 'projectExperience', 'workExperience', ],
        activeKey: 'educationExperience',
        // 教育经历表
        educationExperienceTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '学校名称',
              key: 'schoolName',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '是否统招',
              key: 'recruitment',
              type: JVXETypes.select,
              options:[],
              dictCode:"education_experience",
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '最高学历',
              key: 'educationId',
              type: JVXETypes.select,
              options:[],
              dictCode:"EDUCATION,EDU_NAME,EDU_ID",
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '所学专业',
              key: 'schoolMajor',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '入学日期',
              key: 'schoolIntime',
              type: JVXETypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '毕业日期',
              key: 'schoolOuttime',
              type: JVXETypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
          ]
        },
        // 求职意向表
        positonIntentionTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '期望行业',
              key: 'industryTypeId',
              type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '期望职位',
              key: 'positionTypeId',
              type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '期望城市',
              key: 'addressId',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '期望薪资',
              key: 'salaryExpectation',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
          ]
        },
        // 项目经历表
        projectExperienceTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '项目名称',
              key: 'projectName',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '项目描述',
              key: 'projectAbout',
               type: JVXETypes.textarea,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '项目开始时间',
              key: 'projectStart',
              type: JVXETypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '项目结束时间',
              key: 'projectEnd',
              type: JVXETypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
          ]
        },
        // 工作经历表
        workExperienceTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '公司名称',
              key: 'enterpriseName',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '职位名称',
              key: 'positionName',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '技能擅长',
              key: 'skills',
               type: JVXETypes.textarea,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '当前薪资',
              key: 'positoinMoney',
               type: JVXETypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '入职时间',
              key: 'workIntiime',
              type: JVXETypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '离职时间',
              key: 'workOuttime',
              type: JVXETypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
            {
              title: '工作描述',
              key: 'workAbout',
               type: JVXETypes.textarea,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue:'',
            },
          ]
        },
        url: {
          add: "/resume/employmentResume/add",
          edit: "/resume/employmentResume/edit",
          queryById: "/resume/employmentResume/queryById",
          showStuUrl:'/stu/stu/getStuList',
          educationExperience: {
            list: '/resume/employmentResume/queryEducationExperienceByMainId'
          },
          positonIntention: {
            list: '/resume/employmentResume/queryPositonIntentionByMainId'
          },
          projectExperience: {
            list: '/resume/employmentResume/queryProjectExperienceByMainId'
          },
          workExperience: {
            list: '/resume/employmentResume/queryWorkExperienceByMainId'
          },
        },
        stuList:{},
      }
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
      this.showStu();
    },
    methods: {
      //查询全部学生
      showStu(){
        this.$http.get(this.url.showStuUrl).then((res)=>{
          this.stuList = res.result;
        });
      },
      addBefore(){
        this.educationExperienceTable.dataSource=[]
        this.positonIntentionTable.dataSource=[]
        this.projectExperienceTable.dataSource=[]
        this.workExperienceTable.dataSource=[]
      },
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        this.$nextTick(() => {
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.educationExperience.list, params, this.educationExperienceTable)
          this.requestSubTableData(this.url.positonIntention.list, params, this.positonIntentionTable)
          this.requestSubTableData(this.url.projectExperience.list, params, this.projectExperienceTable)
          this.requestSubTableData(this.url.workExperience.list, params, this.workExperienceTable)
        }
      },
      //校验所有一对一子表表单
        validateSubForm(allValues){
            return new Promise((resolve,reject)=>{
              Promise.all([
              ]).then(() => {
                resolve(allValues)
              }).catch(e => {
                if (e.error === VALIDATE_FAILED) {
                  // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
                  this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
                } else {
                  console.error(e)
                }
              })
            })
        },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)
        return {
          ...main, // 展开
          educationExperienceList: allValues.tablesValue[0].tableData,
          positonIntentionList: allValues.tablesValue[1].tableData,
          projectExperienceList: allValues.tablesValue[2].tableData,
          workExperienceList: allValues.tablesValue[3].tableData,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },

    }
  }
</script>

<style scoped>
</style>